#include "Tray.h"

namespace qtangram
{
Tray::Tray(double viewRange, QWidget* parent) : ContainerWidget(viewRange, parent) {
    setAcceptDrops(true);
}
Tray::Tray(QWidget *parent) : ContainerWidget(2.2,parent) {
    setAcceptDrops(true);
}
void Tray::paintEvent(QPaintEvent*)
{
    QStyleOption o;
    o.initFrom(this);
    TanPainter painter(this);
    style()->drawPrimitive(QStyle::PE_Widget, &o, &painter, this);
    allTansCoordsTo(this);
    for(auto it = tans.begin(); it != tans.end(); ++it) painter.drawTan(*it);
}

void Tray::mousePressEvent(QMouseEvent* event)
{
    if(event->button() == Qt::LeftButton)
    {
        // ToDo:All implement hiding tan in tray and showing in workspace
        deselectAllTans();
        QPointF wpos = CoordinateTransformer::screenToWorld(this,event->pos());
        selectTanAt(wpos);
        repaint();
    }
    else if (event->button() == Qt::RightButton) {
        deselectAllTans();
        QPointF wpos = CoordinateTransformer::screenToWorld(this,event->pos());
        selectTanAt(wpos);
        emit sigRemoveSelectedTans();
    }
}
}
